<?php

namespace app\admin\controller;

use think\facade\Db;

class Bug extends Base
{

    protected function _infoModule()
    {
        return array(
            'info' => array(
                'name' => 'Bug反馈',
                'description' => '管理网站后台管理员',
            ),
            'menu' => array(
                array(
                    'name' => '列表',
                    'url' => url('index'),
                    'icon' => 'list',
                ),
            ),
            '_info' => array(),
        );
    }

    public function index()
    {
        //筛选条件
        $where = array();

        $id = input('id');
        $uid = input('uid');
        $uname = input('uname');
        $title = input('title');
        $content = input('content');

        if ($id) {
            $where[] = ['id', '=', $id];
        }
        if ($uid) {
            $where[] = ['uid', '=', $uid];
        }
        if ($uname) {
            $where[] = ['uname', '=', $uname];
        }
        if ($title) {
            $where[] = ['title', 'like', '%' . $title . '%'];
        }
        if ($content) {
            $where[] = ['content', 'like', '%' . $content . '%'];
        }

        //URL参数
        $pageMaps = array();
        $pageMaps['id'] = $id;
        $pageMaps['uid'] = $uid;
        $pageMaps['uname'] = $uname;
        $pageMaps['title'] = $title;
        $pageMaps['content'] = $content;

        $pageAry = [
            'list_rows' => 15,
            'page' => input('page', 1),
            'path' => 'index',
            'query' => $pageMaps,
        ];

        //查询数据
        $list = model('Bug')->loadList($where, $pageAry);
        if (!empty($list)) {
            foreach ($list as $key => $item) {
                if ($item['uid'] != 0) {
                    $item['uname'] = model('Role')->getWhereValue(['uid' => $item['uid']], 'uname');
                }
            }
        }
        $this->assign('list', $list);
        $this->assign('_page', $list->render());
        $this->assign('pageMaps', $pageMaps);

        $this->fetch('index');
    }

    /**
     * 删除信息
     * @param int $id
     * @return bool 删除状态
     */
    public function del()
    {
        $id = input('id');
        if (empty($id)) {
            returnJson(0, '参数不能为空');
        }

        $userModel = model('Bug');
        if ($userModel->del($id)) {
            returnJson(1, '删除成功！');
        } else {
            returnJson(0, '删除失败');
        }
    }


}
